package ${servicePackage};

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.system.core.view.common.response.CommonPageResponse;
import com.system.core.view.common.response.CommonResponse;
import ${myMapperPackage}.My${servName?cap_first}Mapper;
import ${myModelPackage}.${bizName?cap_first}Model;
import ${myModelPackage}.${bizName?cap_first}Param;
import ${dtoPackage}.${bizName?cap_first}Dto;
import ${dtoPackage}.${bizName?cap_first}Req;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ${servName?cap_first}Service {
	
	private final My${servName?cap_first}Mapper my${servName?cap_first}Mapper;
	
	<#if (resultType=="ResultSet")>
	/**
	 * ${comments!"返回分页数据"}
	 * @param req
	 * @return 分页数据
	 */
	public CommonPageResponse<${bizName?cap_first}Dto> ${bizName?uncap_first}List(${bizName?cap_first}Req req) {
		Page<${bizName?cap_first}Model> page = PageHelper.startPage(req.getPage(), req.getLimit());
		${bizName?cap_first}Param param = new ${bizName?cap_first}Param();
		BeanUtils.copyProperties(req, param);
		List<${bizName?cap_first}Model> models = my${servName?cap_first}Mapper.select${bizName?cap_first}(param);
		List<${bizName?cap_first}Dto> dtos = models.stream().map(${bizName?cap_first}Dto::toDto).collect(Collectors.toList());
		return CommonPageResponse.buildSuccessResult(page.getTotal(), dtos);
	}
	<#else>
	/**
	 * ${comments!"返回单个对象数据"}
	 * @param req
	 * @return 单条数据
	 */
	public CommonDataResponse<${bizName?cap_first}Dto> get${bizName?cap_first}(${bizName?cap_first}Req req) {
		${bizName?cap_first}Param param = new ${bizName?cap_first}Param();
		BeanUtils.copyProperties(req, param);
		${bizName?cap_first}Model models = my${servName?cap_first}Mapper.get${bizName?cap_first}(param);
		${bizName?cap_first}Dto dto = new ${bizName?cap_first}Dto();
		if(models == null) {
			return CommonDataResponse.buildFailureResult("未查询到数据", dto);
		} else {
			BeanUtils.copyProperties(models, dto);
			return CommonDataResponse.buildSuccessResult(dto);
		}
	}
	</#if>
}